package com.edu.policy.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.policy.domin.PageDto;
import com.edu.policy.model.UmsResource;
import com.edu.policy.service.AppUmsAdminCacheService;
import com.edu.policy.service.AppUmsResourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 后台资源管理Service实现类
 * Created by chz on 2020/2/2.
 */
@RequiredArgsConstructor
@Service
public class AppUmsResourceServiceImpl extends UmsResourceServiceImpl implements AppUmsResourceService {

    private final AppUmsAdminCacheService adminCacheService;


    @Override
    public PageDto<UmsResource> list(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize, Integer currentPage) {
        PageDto<UmsResource> result = new PageDto<>();
        Page<UmsResource> page = Page.of(currentPage, pageSize);
        Page<UmsResource> tempResult = this
                .lambdaQuery()
                .eq(categoryId != null, UmsResource::getCategoryId, categoryId)
                .like(StrUtil.isNotEmpty(urlKeyword),UmsResource::getUrl, urlKeyword)
                .like(StrUtil.isNotEmpty(nameKeyword),UmsResource::getName, nameKeyword)
                .page(page);
        result.setList(tempResult.getRecords());
        result.setPages(tempResult.getPages());
        result.setTotal(tempResult.getTotal());
        result.setCurrentPage(tempResult.getCurrent());
        return result;
    }

    @Override
    public List<UmsResource> listAll() {
        return list();
    }
}
